<?php
namespace app\admin\controller;

class Team extends BaseAdmin
{
    public function listers()
    {
        $list=db("team")->order(["sort asc","id desc"])->paginate(20);
        $this->assign("list",$list);
        
        $page=$list->render();
        $this->assign("page",$page);
        
        return \view("lister");
    }
    public function add()
    {
        return \view("add");
    }
    public function save(){
        $data=\input("post.");
        if(!is_string(input('image'))){
            $data['image']=uploads('image');
        }
        if(!is_string(input('images'))){
            $data['images']=uploads('images');
        }
        if(input('status')){
            $data['status']=1;
        }
        $data['time']=\time();
        $re=db("team")->insert($data);
        if($re){
            $this->success("添加成功！",url('add'));
        }else{
            $this->error("添加失败！");
        }
    }
    public function sort(){
        $data=input('post.');
        $news=db('team');
        foreach ($data as $id => $sort){
            $news->where(array('id' => $id ))->setField('sort' , $sort);
        }
        $this->redirect('listers');
    }
    public function delete(){
        $id=input('id');
        $del=db("team")->where("id=$id")->delete();
        $this->redirect('listers');
    }
    public function change(){
        $id=\input("id");
        $re=db("team")->where("id=$id")->find();
        if($re['status'] == 0){
            $res=db("team")->where("id=$id")->setField("status",1);
        }else{
            $res=db("team")->where("id=$id")->setField("status",0);
        }
        if($res){
            echo '1';
        }else{
            echo '0';
        }
    }
    public function modifys()
    {
        $id=\input('id');
        $re=db("team")->where("id=$id")->find();
        $this->assign("re",$re);
        return \view("modifys");
    }
    public function usave(){
        $id=\input("id");
        $re=db("team")->where("id=$id")->find();
        if($re){
            $data=\input("post.");
            if(!is_string(input('image'))){
                $data['image']=uploads('image');
            }else{
                $data['image']=$re['image'];
            }
            if(!is_string(input('images'))){
                $data['images']=uploads('images');
            }else{
                $data['images']=$re['images'];
            }
            if(input('status')){
                $data['status']=1;
            }else{
                $data['status']=$re['status'];
            }
            
    
            $re=db("team")->where("id=$id")->update($data);
            if($re){
                $this->success("修改成功！",url('listers'));
            }else{
                $this->error("修改失败",url("listers"));
            }
        }else{
            $this->error("参数错误",url("listers"));
        }
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}